// hotel-management-frontend/src/App.js

import React from "react";
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Navigate,
} from "react-router-dom";
import AppLayout from "./components/Layout";

// Admin components
import RoomManagement from "./admin/RoomManagement";
import GuestManagement from "./admin/GuestManagement";
import CheckinManagement from "./admin/CheckinManagement";
import Statistics from "./admin/Statistics";
import Dashboard from "./admin/Dashboard";
import BulkImport from "./admin/BulkImport";
import MenuItemManagement from "./admin/MenuItemManagement"; // <--- 新增导入
import CheckinDetails from "./admin/CheckinDetails"; // <--- 新增导入，用于入住详情
import "antd/dist/reset.css"; // 确保样式已引入
import "@ant-design/v5-patch-for-react-19";

// Client components
import ClientHistory from "./client/History";
import ClientProfile from "./client/Profile";

// Admin Routes Wrapper
const AdminRoutes = () => (
  <AppLayout isAdmin={true}>
    <Routes>
      <Route path="dashboard" element={<Dashboard />} />
      <Route path="rooms" element={<RoomManagement />} />
      <Route path="guests" element={<GuestManagement />} />
      <Route path="checkins" element={<CheckinManagement />} />
      <Route path="checkins/:id" element={<CheckinDetails />} />{" "}
      {/* <--- 新增入住详情路由 */}
      <Route path="statistics" element={<Statistics />} />
      <Route path="bulk-import" element={<BulkImport />} />
      <Route path="menu-items" element={<MenuItemManagement />} />{" "}
      {/* <--- 新增商品管理路由 */}
      <Route path="*" element={<Navigate to="dashboard" replace />} />
    </Routes>
  </AppLayout>
);

function App() {
  return (
    <Router>
      <Routes>
        {/* Admin section */}
        <Route path="/admin/*" element={<AdminRoutes />} />

        {/* Client section */}
        <Route
          path="/"
          element={
            <AppLayout isAdmin={false}>
              <ClientHistory />
            </AppLayout>
          }
        />
        <Route
          path="/client/history"
          element={
            <AppLayout isAdmin={false}>
              <ClientHistory />
            </AppLayout>
          }
        />
        <Route
          path="/client/profile"
          element={
            <AppLayout isAdmin={false}>
              <ClientProfile />
            </AppLayout>
          }
        />

        {/* Fallback route */}
        <Route path="*" element={<Navigate to="/" replace />} />
      </Routes>
    </Router>
  );
}

export default App;
